package com.nfit.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.UUID;

@Configuration
public class OthersConfig {

    // 声明 fanout 交换机
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("broadcast_exchange");
    }

    // 声明队列（自动生成唯一队列名）
    @Bean
    public Queue userQueue() {
        String queueName = "dynamicQueue-" + UUID.randomUUID().toString();
        return new Queue(queueName, true, false, true);
    }

    // 将队列绑定到 fanout 交换机
    @Bean
    public Binding binding(FanoutExchange fanoutExchange, Queue queue) {
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }
}
